package cn.yunhe.services;

import cn.yunhe.dao.IOrderDao;
import cn.yunhe.entity.Order;
import cn.yunhe.entity.OrderCon;
import cn.yunhe.util.SqlSessionFactoryUtil;
import net.sf.json.JSONArray;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.List;

/**
 * 李非凡
 * 商家订单展示
 */
public class OrderShowService {
    SqlSession sqlSession = null;
    IOrderDao iOrderDao = null;

    /**
     * 商家订单展示
     * @param mid
     */
    public JSONArray showOrder(int mid){
        List<Order> orderList=new ArrayList<>();
        try{
            sqlSession = SqlSessionFactoryUtil.getSqlSession();
            iOrderDao = sqlSession.getMapper(IOrderDao.class);
            //获取所有订单
            orderList = iOrderDao.getOrder(mid);
        }finally {
            sqlSession.close();
        }
        JSONArray jsonArray=new JSONArray();
        jsonArray.addAll(orderList);
        return jsonArray;
    }

    /**
     * 获取订单总数
     * @param mid
     * @return
     */
    public int getOrderCount(int mid){
        int count=0;
        try{
            sqlSession = SqlSessionFactoryUtil.getSqlSession();
            iOrderDao = sqlSession.getMapper(IOrderDao.class);
            count = iOrderDao.getOrderCount(mid);
        }finally {
            sqlSession.close();
        }
        return count;
    }
}
